T = 33.333

# 

Fs = [
    ["f0", 32.558073],     # genFromMemory
    ["f1", 20.366043],     # resize
    ["f2", 20.337533],     # yolo_preprocess
    ["f3", 16.543695],     # groupByBatch
    # ["f4", 3.1098483],   # transferToDeviceMemory
    # ["f5", 15.7387],     # yolo_inference
    # ["f6", 18.757815],   # transferToHostMemory
    ["f7", 21.85893],      # splitByShape
    ["f8_0", 19.575439],   # yolo_postprocess-0
    ["f8_1", 19.575439],   # yolo_postprocess-1
    ["f9", 3.9737017],     # cropWithInput
    ["f10", 2.6974067],    # resize
    ["f11", 11.177275],    # retinanet_preprocess
    ["f12", 4.8440983],    # groupByBatch
    # ["f13", 0.855828],   # transferToDeviceMemory
    # ["f14", 2.536893],   # retinanet_inference
    # ["f15", 0.950427],   # transferToHostMemory
    ["f16", 1.4400333],    # splitByShape
    ["f17", 7.002315],     # retinanet_postprocess 
    ["f18", 0.1484717],    # cropWithInput
    ["f19", 0.024415],     # resize
    ["f20", 0.0419717],    # lprnet_preprocess
    ["f21", 0.0319117],    # groupByBatch
    # ["f22", 0.0090317],  # transferToDeviceMemory
    # ["f23", 0.0859483],  # lprnet_inference
    # ["f24", 0.0069983],  # transferToHostMemory
    ["f25", 0.01138],      # splitByShape
    ["f26", 0.0598583],    # lprnet_postprocess
    ["f27",  0.111060],    # groupByRequestId
    ["f28", 10.25808]      # markAndSave
]

Boxes = [["f5", "f14", "f23"],["f4", "f6", "f13", "f15", "f22", "f24"]]
Costs = [18.3615413, 23.76493]

for item in Fs:
    name, cost = item[0],item[1]
    max_index = -1
    max_remain = 0
    for i in range(len(Costs)):
        if cost + Costs[i] <= T:
            remain = T - (cost + Costs[i])
            if remain > max_remain:
                max_index = i
                max_remain = remain
    if max_index == -1:
        # 添加新箱子
        Boxes.append([name])
        Costs.append(cost)
    else:
        Boxes[max_index].append(name)
        Costs[max_index] += cost

for i in Boxes:
    print(i)
print()
for i in Costs:
    print(i)


